//
// Copyright (C) 2024 Kumo group inc.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#include <krpc/rpc/admin/handlers.h>
#include <krpc/rpc/server.h>               // Server

namespace krpc::admin {

    void health_func(const RestfulRequest *req, RestfulResponse *resp) {
        Controller *cntl = req->controller();
        const Server* server = cntl->server();
        if (server->options().health_reporter) {
            server->options().health_reporter->GenerateReport(cntl, nullptr);
        } else {
            resp->set_status_code(200);
            resp->set_content_type(RestfulResponse::TEXT_PLAIN);
            resp->set_body("OK");
        }
    }

    void version_func(const RestfulRequest *req, RestfulResponse *resp) {
        Controller *cntl = req->controller();
        const Server* server = cntl->server();
        resp->set_status_code(200);
        resp->set_content_type(RestfulResponse::TEXT_PLAIN);
        if (server->version().empty()) {
            resp->set_body("unknown");
        } else {
            resp->set_body(server->version());
        }
    }
}  // namespace krpc::admin
